1   /*
2    * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
3    * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4    *
5    * This code is free software; you can redistribute it and/or modify it
6    * under the terms of the GNU General Public License version 2 only, as
7    * published by the Free Software Foundation.
8    *
9    * This code is distributed in the hope that it will be useful, but WITHOUT
10   * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11   * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
12   * version 2 for more details (a copy is included in the LICENSE file that
13   * accompanied this code).
14   *
15   * You should have received a copy of the GNU General Public License version
16   * 2 along with this work; if not, write to the Free Software Foundation,
17   * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18   *
19   * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20   * or visit www.oracle.com if you need additional information or have any
21   * questions.
22   */
23  
24  /*
25   * @test
26   * @bug 6941948
27   * @summary Make sure that EASTERN_ARABIC works with the enum interface.
28   */
29  
30  import java.awt.font.NumericShaper;
31  import java.util.EnumSet;
32  import static java.awt.font.NumericShaper.*;
33  
34  public class EasternArabicTest {
35      static NumericShaper ns_old, ns_new;
36      static boolean err = false;
37  
38      static String[][] testData = {
39          // Arabic "October 10"
40          {"\u0623\u0643\u062a\u0648\u0628\u0631 10",
41           "\u0623\u0643\u062a\u0648\u0628\u0631 \u06f1\u06f0"}, // EASTERN_ARABIC digits
42  
43          // Tamil "Year 2009"
44          {"\u0b86\u0ba3\u0bcd\u0b9f\u0bc1 2009",
45           "\u0b86\u0ba3\u0bcd\u0b9f\u0bc1 \u0be8\u0be6\u0be6\u0bef"},
46          // "\u0be800\u0bef is returned by pre-JDK7 because Tamil zero was not
47          //  included in Unicode 4.0.0.
48  
49          // Ethiopic "Syllable<HA> 2009"
50          {"\u1200 2009",
51           "\u1200 \u136a00\u1371"},
52          // Ethiopic zero doesn't exist even in Unicode 5.1.0.
53      };
54  
55      public static void main(String[] args) {
56          ns_old = getContextualShaper(TAMIL|ETHIOPIC|EASTERN_ARABIC|ARABIC|THAI|LAO,
57                                       EUROPEAN);
58          ns_new = getContextualShaper(EnumSet.of(Range.THAI,
59                                                  Range.TAMIL,
60                                                  Range.ETHIOPIC,
61                                                  Range.EASTERN_ARABIC,
62                                                  Range.ARABIC,
63                                                  Range.LAO),
64                                       Range.EUROPEAN);
65  
66  
67          StringBuilder cData = new StringBuilder();
68          StringBuilder cExpected = new StringBuilder();
69          for (int i = 0; i < testData.length; i++) {
70              String data = testData[i][0];
71              String expected = testData[i][1];
72              test(data, expected);
73              cData.append(data).append(' ');
74              cExpected.append(expected).append(' ');
75          }
76          test(cData.toString(), cExpected.toString());
77  
78          if (err) {
79              throw new RuntimeException("shape() returned unexpected value.");
80          }
81      }
82  
83      private static void test(String data, String expected) {
84          char[] text = data.toCharArray();
85          ns_old.shape(text, 0, text.length);
86          String got = new String(text);
87  
88          if (!expected.equals(got)) {
89              err = true;
90              System.err.println("Error with traditional range.");
91              System.err.println("  text = " + data);
92              System.err.println("  got = " + got);
93              System.err.println("  expected = " + expected);
94          } else {
95              System.err.println("OK with traditional range.");
96              System.err.println("  text = " + data);
97              System.err.println("  got = " + got);
98              System.err.println("  expected = " + expected);
99          }
100 
101         text = data.toCharArray();
102         ns_new.shape(text, 0, text.length);
103         got = new String(text);
104 
105         if (!expected.equals(got)) {
106             err = true;
107             System.err.println("Error with new Enum range.");
108             System.err.println("  text = " + data);
109             System.err.println("  got = " + got);
110             System.err.println("  expected = " + expected);
111         } else {
112             System.err.println("OK with new Enum range.");
113             System.err.println("  text = " + data);
114             System.err.println("  got = " + got);
115             System.err.println("  expected = " + expected);
116         }
117     }
118 }